package cn.itcast.user.pojo;

import lombok.Data;

/**
 * @author danDong
 * @date 2025-05-23 08:50:49
 */
@Data
public class AAA {
    private static Integer count = 0;

    public static synchronized void setCount() {
        setCount2();
        for (int i = 0; i < 10000000; i++) {
            System.out.println("11111");
            count++;
        }
    }

    public static synchronized void setCount2() {
        setCount();
        System.out.println("22222");
    }

    public static synchronized int getCount() {
        return count;

    }

    public static void main(String[] args) throws InterruptedException {
        AAA aaa = new AAA();
        Thread t1 = new Thread(() -> aaa.setCount());
        t1.start();
        Thread t2 = new Thread(() -> aaa.setCount());
        t2.start();
        Thread t3 = new Thread(() -> aaa.setCount());
        t3.start();
        Thread t4 = new Thread(() -> aaa.setCount());
        t4.start();
        Thread t5 = new Thread(() -> aaa.setCount());
        t5.start();
        t1.join();
        t2.join();
        t3.join();
        t4.join();
        t5.join();
        System.out.println(aaa.getCount());
    }
}
